package com.example.richobject.recyc_Adaper;

import android.content.Context;
import android.view.LayoutInflater;

import java.io.UnsupportedEncodingException;
import java.util.List;


/**
 * 作者：Mio
 * 时间：2019/4/8
 * 邮箱:17379235050@163.com
 * 描述: RecyclerView适配器
 */
public abstract class RecyclerViewAdapter<T> extends MultiItemTypeAdapter<T> {
    protected Context mContext;
    protected int mLayoutId;
    protected List mDatas;
    private int count = 0;
    protected LayoutInflater mInflater;

    public List getmDatas() {
        return mDatas;
    }

    public void setmDatas(List mDatas) {
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    public RecyclerViewAdapter(final Context context, final int layoutId, List<T> datas) {
        super(context, datas);
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mLayoutId = layoutId;
        mDatas = datas;

        addItemViewDelegate(new ItemViewDelegate<T>() {
            @Override
            public int getItemViewLayoutId() {
                return layoutId;
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return true;
            }

            @Override
            public void convert(RecyclerViewHolder holder, T t, int position) throws UnsupportedEncodingException {
                RecyclerViewAdapter.this.convert(holder, t, position);
            }
        });
    }


    protected abstract void convert(RecyclerViewHolder holder, T t, int position) throws UnsupportedEncodingException;

}

